#include "Map.h"


template<typename Key, typename Value>
Map<Key, Value>::MapNode::MapNode()
{}

template<typename Key, typename Value>
bool Map<Key, Value>::MapNode::operator>(Map<Key, Value>::MapNode n)
{
	if(key > n.key)
		return true;
	else
		return false;
}

template<typename Key, typename Value>
bool Map<Key, Value>::MapNode::operator==(Map<Key, Value>::MapNode n)
{
	if(key == n.key)
		return true;
	else
		return false;
}

template<typename Key, typename Value>
Map<Key, Value>::Map()
{
	map = Tree<MapNode>();
}

template<typename Key, typename Value>
void Map<Key, Value>::add(Key key, Value value)
{
	Map<Key, Value>::MapNode n = Map<Key, Value>::MapNode();
	n.key = key;
	n.value = value;
	map.add(n); 
	
}

template<typename Key, typename Value>
Value Map<Key, Value>::get(Key key)
{
	Map<Key, Value>::MapNode n = Map<Key, Value>::MapNode();
	n.key = key;
	Node<Map<Key,Value>::MapNode>* node = map.find(n);
	if(node == NULL) 
		return Value(); //empty value.
	else
		return node->value.value;
}

template<typename Key, typename Value>
bool Map<Key, Value>::find(Key key)
{
	Map<Key, Value>::MapNode n = Map<Key, Value>::MapNode();
	n.key = key;
	Node<Map<Key,Value>::MapNode>* node = map.find(n);
	if(node == NULL) 
		return false; //empty value.
	else
		return true;
}

template<typename Key, typename Value>
void Map<Key, Value>::remove(Key key)
{
	Map<Key, Value>::MapNode n = Map<Key, Value>::MapNode();
	n.key = key;
	map.remove(n);
}

template<typename Key, typename Value>
void Map<Key, Value>::set(Key key, Value value)
{
	if(find(key) == false)
	{
		add(key, value);
		return;
	}
	else
	{
		Map<Key, Value>::MapNode n = Map<Key, Value>::MapNode();
		n.key = key;
		Node<Map<Key,Value>::MapNode>* node = map.find(n);
		node->value.value = value;
		return;
	}
}

